package com.LA_houseLease.admin.controller.apartment;



import com.LA_houseLease.admin.service.FileService;
import com.LA_houseLease.common.result.Result;
import io.minio.errors.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
@CrossOrigin(origins = "*")
@Slf4j
@Tag(name = "文件管理")
@RequestMapping("/admin/file")
@RestController
public class FileUploadController {

    @Autowired
    private FileService fileService;

    @Operation(summary = "上传文件")
    @PostMapping("upload")
    public Result<String> upload(@RequestParam MultipartFile file) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        //MultipartFile:Spring框架提供的专门用来接收上传文件的接口
        log.warn("上传文件--FileUploadController.upload");
        String url=fileService.upload(file);
        return Result.ok(url);
    }

}
